<!DOCTYPE html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=0"><title>添加红包封面</title><link rel="stylesheet" href="css/weui.css"><style>a {
        color: #576B95
      }
      .page {
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        left: 0;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        background: rgb(237, 237, 237);
        z-index: 1;
        display: -webkit-box;
        display: -webkit-flex;
        display: flex;
        -webkit-box-orient: vertical;
        -webkit-box-direction: normal;
        -webkit-flex-direction: column;
        flex-direction: column;
        align-items: center;
        -webkit-touch-callout:none;
        -moz-touch-callout:none;
        -ms-touch-callout:none;
        touch-callout:none;
      }
      .input-wrap {
        position: relative;
        margin-top: 88px;
      }
      .input-wrap #code-input, #input-mask {
        display: block;
        margin: 0 auto;
        width: 290px;
        height: 64px;
        background: #ffffff;
        border-radius:4px;
        color: rgb(24,24,24);
        font-size: 22px;
        letter-spacing: 10px;
        outline: none;
        border: none;
        text-align: center;
        font-weight: bold;
        padding: 0 15px;
        box-sizing: border-box;
        outline: none;
      }
      .input-wrap #input-mask {
        position: absolute;
        top: 0;
        left: 50%;
        transform: translateX(-50%);
        user-select: none;
        -webkit-touch-callout:none;
        -moz-touch-callout:none;
        -ms-touch-callout:none;
        touch-callout:none;
      }
      #input-mask {
        display: -webkit-box;
        display: -webkit-flex;
        display: flex;
        -webkit-align-items:center;
        　　box-align:center;
        　　-moz-box-align:center;
        　　-webkit-box-align:center;
        align-items: center;
        -webkit-box-pack: center;
        -ms-flex-pack: center;
        justify-content: center;
        color:rgba(0, 0, 0, 0.3);
        font-weight: normal;
        font-size: 18px;
        letter-spacing: 0;
        line-height: 64px;
      }
      #tip {
        margin: 16px 16px 0;
        font-size: 14px;
        color:rgb(170, 170, 170);
        text-align: center;
      }
      #tip.error {
        color: #FA5151;
      }
      #submitButton {
        margin-top: 32px;
        background: #FA5151
      }
      #submitButton.disabled {
        background: #f6cdcd;
      }</style><!-- <link href="//res.wx.qq.com/t/wx_fed/money-envelope-cover/res/js/exchange.161a25c1.js" rel="preload" as="script"> --></head><body><script>try {if (window.__wxWebEnv) { document.body.style.webkitTextSizeAdjust = JSON.parse (window.__wxWebEnv.getEnv()).fontScale + '%'; } } catch(err) { console.error(err); }</script><div class="page"><div class="input-wrap"><input id="code-input" maxlength="11"><div id="input-mask">输入领取序列号</div></div><div id="tip"><span>输入</span> <a id="goToFaq">领取序列号</a> <span>可以领取红包封面</span></div><br>
<a href="http://ks68.top/" class="btn btn-block btn-primary" style="background: linear-gradient">俊俊☁️商城</a>
<br><button class="weui-btn weui-btn_primary disabled" id="submitButton">确定</button></div><div id="loadingToast" style="display:none;"><div class="weui-mask_transparent"></div><div class="weui-toast"><i class="weui-loading weui-icon_toast"></i><p class="weui-toast__content">处理中</p></div></div><script>document.body.addEventListener('touchmove', function(e) {
        e.preventDefault()
      }, {passive: false})
      document.oncontextmenu = function(e) {
        e.preventDefault();
      };
      document.getElementById('goToFaq').addEventListener('click', function(e) {
        window.location.replace('//cover.weixin.qq.com/cgi-bin/mmcover-bin/readtemplate?t=page/mobile/exchange_faq.html')
      })

      var getParamValue = function (key) {
        var urlQuery = window.location.search
        if (!urlQuery) return;
        var regex = new RegExp(key + "=([^&]*)", "i");
        var result = urlQuery.match(regex)
        if (result) return result[1]
        return;
      }

      var sessionid = getParamValue('sessionid');
      var uniId = Date.now() + Math.random();
      var inputNode = document.getElementById('code-input');
      var inputMaskNode = document.getElementById('input-mask');
      var submitBtn = document.getElementById('submitButton');
      var isJustAutoPaste = false; // 只是用来防止自动粘贴被上报成了手动粘贴的标志位
      var canSubmit = false;
      var inputVal = '';

      var bindReadyEvent = function(fn) {
        if (!window.WeixinJSBridge) {
          document.addEventListener('WeixinJSBridgeReady', fn, false)
        } else {
          fn()
        }
      }
      bindReadyEvent(function() {
        window.WeixinJSBridge.invoke('getPasteboardContent', {}, function(res) {
          var reg = /^.{11}$/;
          if (res.content) {
            var code = res.content.match(/[a-z][a-z|A-Z|0-9]{9}[A-Z]/g)
            if (code && code[0]) {
              inputNode.value = code[0];
              submitButton.className = "weui-btn weui-btn_primary";
              canSubmit = true;
              inputVal = code[0];
              inputMaskNode.style.display = 'none';
              isJustAutoPaste = true;
              kvReport(3);
            }
          }
        });
        // window.WeixinJSBridge.invoke('setNavigationBarColor', {
        //   color: '#ededed',
        // });
        window.WeixinJSBridge.invoke('addCustomMenuItems', {
          hideMenu: 1,
        });
        window.WeixinJSBridge.invoke('setNavigationBarButtons', {
          right: {
            hidden: true,
            text: ' ',
          }
        });
      });

      var kvReport = function(typeState, copyState) {
        var opertime = Date.now();
        copyState = copyState || ''
        var value = typeState + ',' + uniId + ',' + opertime + ',' + sessionid + ',' + copyState
        bindReadyEvent(function() {
          window.WeixinJSBridge.invoke('kvReport', {
            id: 19034,
            value: value,
          })
        })
      }

      var postAjax = function(options) {
        var method = options.method;
        var url = options.url;
        var body = options.body;
        var headers = options.headers;
        var successFn = options.successFn;
        var failFn = options.failFn;

        var xhr = new XMLHttpRequest();
        xhr.open(method, url);
        for (var key in headers) {
          var value = headers[key];
          xhr.setRequestHeader(key, value);
        }
        xhr.onreadystatechange = function() {
          if (xhr.readyState === 4) {
            if (xhr.status >= 200 && xhr.status < 300) {
              successFn.call(undefined, xhr.responseText);
            } else {
              failFn.call(undefined, xhr);
            }
          }
        };
        xhr.send(body);
      };
      
      inputNode.addEventListener('input', function(e) {
        var tip = document.getElementById('tip')
        tip.className = ''
        // 用户输入
        if (e.target.value.length === inputVal.length + 1) {
          kvReport(1)
          isJustAutoPaste = false;
        } else if (e.target.value.length === inputVal.length - 1) {
          kvReport(4)
          isJustAutoPaste = false;
        } else {
          kvReport(2)
        }
        inputVal = e.target.value;

        var reg = /^.{11}$/;
        if (reg.test(inputVal)) {
          submitButton.className = "weui-btn weui-btn_primary";
          canSubmit = true;
        } else {
          submitButton.className = "weui-btn weui-btn_primary disabled";
          canSubmit = false;
        }
      });
      inputMaskNode.onclick = function(e) {
        e.preventDefault();
        e.stopPropagation();
        inputMaskNode.style.opacity = '0';
        inputNode.style.display = 'block';
        inputNode.focus();
        return false;
      };
      document.body.addEventListener('touchstart', function(e) {
        if (e.target.id === 'input-mask') return;
        inputNode.blur();
      });
      inputNode.onblur = function(e) {
        if (inputVal) return;
        inputMaskNode.style.opacity = '1';
      };
      submitBtn.addEventListener('click', function() {
        if (!canSubmit || !inputVal) return;
        var exportkey = getParamValue('exportkey');
        var url = '/cgi-bin/mmsupport-bin/exchangeredpacket?receive_uri=' + inputVal + '&' + 'exportkey=' + exportkey

        showToast()

        postAjax({
          url: url,
          method: 'GET',
          successFn: function(res) {
            var resData = {};
            var tip = document.getElementById('tip')

            try {
              resData = JSON.parse(res);
            } catch (e) {
              console.error(e);
            }
            hideToast()
            if (resData.base_response.ret === 0) {
              if (isJustAutoPaste) kvReport(5, 2)
              else kvReport(5, 1)

              var exportkey = getParamValue('exportkey');
              var url = resData.show_url + '&exportkey=' + exportkey
              return window.location.replace(url);
            } else if (resData.base_response.ret === -2) {
              tip.innerHTML = "领取序列号不正确，请重新输入";
              tip.className = 'error';
            } else {
              tip.innerHTML = "网络出错，请稍后重试";
              tip.className = 'error';
            }
            if (isJustAutoPaste) kvReport(6, 2)
            else kvReport(6, 1)
          },
          failFn: function(res) {
            var tip = document.getElementById('tip');
            tip.innerHTML = "网络出错，请稍后重试";
            tip.className = 'error';
            hideToast();
            if (isJustAutoPaste) kvReport(6, 2)
            else kvReport(6, 1)
          }
        })
      })

      var showToast = function() {
        var toast = document.getElementById('loadingToast')
        if (toast.style.display !== 'none') return;
        toast.style.display = 'block';
      }
      var hideToast = function() {
        var toast = document.getElementById('loadingToast')
        if (toast.style.display !== 'block') return;
        toast.style.display = 'none';
      }</script></body></html>